In [13]:
from scipy.signal import butter
from scipy.signal import lfilter
from sklearn.preprocessing import StandardScaler
import random
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
We define our filter here in which we specify the low cut (0.5Hz), the high cut (30Hz), the frecuency (128Hz) and the order of the filter.
based on: http://scipy-cookbook.readthedocs.io/items/ButterworthBandpass.html
In [15]:
def butter_bandpass(lowcut, highcut, fs, order=4):
nyq = 0.5 * fs
low = lowcut / nyq
high = highcut / nyq
b, a = butter(order, [low, high], btype='band')
return b, a
b, a = butter_bandpass(0.5, 30.0, 128.0)
In [16]:
path = "../../Dataset/Test/EEG_Test_Sorted.csv"
file_name = "Filtered_file.csv"
df = pd.read_csv(path)
labels = ['AF3','F7','F3','FC5','T7','P7','O1','O2','P8','T8','FC6','F4','F8','AF4']
filtered_dataset = pd.DataFrame(columns=['AF3','F7','F3','FC5','T7','P7','O1','O2','P8','T8','FC6','F4','F8','AF4','Class'])
for i in labels:
temp = lfilter(b, a, df[i])
filtered_dataset[i] = temp
filtered_dataset['Class'] = df['Class']
filtered_dataset.to_csv(file_name, index=False)